/**
 * websocket接口前端js文件
 */
// import { ElMessage } from "element-ui";
import getStorage from '../utils/getStorage'
import { Message } from 'element-ui';


let socket= null;
let socketUrl= "ws://localhost:8888/websocket/";

let userId= getStorage.getAxiosUserId();

export default {
     openSocket() {
		const socketUrl = "ws://localhost:8888/websocket/";
        if(socket!=null){
            socket.close();
            socket=null;
        }
        // socketUrl = socketUrl+userId;
        socket = new WebSocket(socketUrl+""+userId);
        //打开事件
        socket.onopen = function() {
            console.log("websocket已打开");
        };
        //获得消息事件
        socket.onmessage = function(msg) {
            console.log(msg.data);
            //发现消息进入,开始处理前端触发逻辑
            // this.showMessage(msg.data);
        };
        //关闭事件
        socket.onclose = function() {
            console.log("websocket已关闭");
        
        };
        //发生了错误事件
        socket.onerror = function() {
            console.log("websocket发生了错误");
        }
    },
    cloesWebSocket(){
        socket.onclose = function() {
            console.log("websocket已关闭");
        };
    },
    showMessage (msg) { {
        Notification({
               title: '请求成功',
               message: msg,
               type: 'success'
             });
}
}
}


